# Maintainer: Francis Giraldeau <francis.giraldeau@nrc-cnrc.gc.ca>

_realname=cgns
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.1.1
pkgrel=1
pkgdesc="CFD General Notation System library and tools (mingw-w64)"
arch=('any')
url="https://cgns.github.io"
license=('zlib')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake")
depends=("${MINGW_PACKAGE_PREFIX}-hdf5")
source=("${_realname}-${pkgver}.tar.gz"::https://github.com/CGNS/CGNS/archive/v${pkgver}.tar.gz)
sha256sums=('055d345c3569df3ae832fb2611cd7e0bc61d56da41b2be1533407e949581e226')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_BUILD_TYPE=Release \
    -DCGNS_ENABLE_HDF5=ON \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ../${_realname}-${pkgver}

  make
}

package() {
  cd build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install

  # license
  install -D -m644 ${srcdir}/${_realname}-${pkgver}/license.txt \
  ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
